<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/20 0020
 * Time: 上午 10:45
 */

namespace Home\Controller;
use Think\Controller;

class CollectController extends Controller{
    protected $model = null;
    public function __construct(){
        parent::__construct();
        $this->model = D('Home/collect');
    }

    //获取当前用户的某个物资编码的收藏状态
    public function get_collect_type(){
        $userid = I('get.userid');
        $wzno = I('get.wzno');
        if($this->model->where("user_id='{$userid}' and wzno={$wzno}")->find()){
            $this->ajaxReturn(true);
        }else{
            $this->ajaxReturn(false);
        }
    }

    //删除当前用户和该物资编码的删除
    public function del_collect(){
        $userid = I('get.userid');
        $wzno = I('get.wzno');
        if($this->model->where("user_id='{$userid}' and wzno={$wzno}")->delete()){
            $this->ajaxReturn(true);
        }else{
            $this->ajaxReturn(false);
        }
    }

    //添加当前用户和该物资编码的收藏
    public function add_collect(){
        $userid = I('get.userid');
        $wzno = I('get.wzno');
        if($this->model->add(array(
            'user_id' => $userid,
            'wzno' => $wzno
        ))){
            $this->ajaxReturn(true);
        }else{
            $this->ajaxReturn(false);
        }
    }

    //当前用户的所有收藏信息
    public function collect(){
        $userid = I('get.userid');
        $info = $this->model->search($userid);
        $this->assign(array(
            'title' => '我的收藏',
            'page_title' => '我的',
            'info' => $info,
        ));
        $this->display();
    }
}